package com.rm.zeyou.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.rm.zeyou.entity.Technician;
import com.rm.zeyou.entity.User;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.UserInviteService;
import com.rm.zeyou.util.login.LoginUtil;
import com.rm.zeyou.util.login.TechnicianLoginUtil;
import com.rm.zeyou.vo.response.SelectUserInviteTechnicianResponseVo;
import com.rm.zeyou.vo.response.SelectUserInviteUserResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 * 用户邀请表 前端控制器
 * </p>
 *
 * @author YanYang
 * @since 2025-03-12 17:23:41
 */
@Api(tags = "邀请相关")
@RestController
@RequestMapping("/api/userInvite")
public class UserInviteController {
    @Resource
    private UserInviteService userInviteService;
    @Resource
    private LoginUtil loginUtil;
    @Resource
    private TechnicianLoginUtil technicianLoginUtil;

    @ApiOperation("查用户邀请记录")
    @GetMapping("selectUserInviteByUserId")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<SelectUserInviteUserResponseVo> selectUserInviteUser() {
        User user = loginUtil.getUser();
        return userInviteService.selectUserInviteUser(user.getId());
    }

    @ApiOperation("查用户邀请技师记录")
    @GetMapping("selectUserInviteTechnician")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<SelectUserInviteTechnicianResponseVo> selectUserInviteTechnician() {
        User user = loginUtil.getUser();
        return userInviteService.selectUserInviteTechnician(user.getId());
    }


    @ApiOperation("邀请好友")
    @GetMapping("inviteUser")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Map<String, String>> inviteUser(@RequestParam Integer type) throws Exception {
        User user = loginUtil.getUser();
        return userInviteService.inviteUser(user, type);
    }

    @ApiOperation("邀请好友")
    @GetMapping("inviteTechnician")
    @SaCheckLogin(type = "technician")
    public ApiRestResponse<Map<String, String>> inviteTechnician(@RequestParam Integer type) throws Exception {
        Technician technician = technicianLoginUtil.getTechnician();
        return userInviteService.inviteTechnician(technician, type);
    }
}
